//
//  AddBandCardInfoViewController.m
//  NewPro
//
//  Created by RYX on 2018/10/14.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "AddBandCardInfoViewController.h"
#import "ConfirmPhoneNumViewController.h"
#import "BankCarList.h"
#import "BandCardAddParametersModel.h"

@interface AddBandCardInfoViewController ()
{
    __weak IBOutlet UITextField *bankNameTf;
    __weak IBOutlet UITextField *bankTypeTf;
    __weak IBOutlet UITextField *phoneNum;
}
@end

@implementation AddBandCardInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavBarWithTitle:@"填写银行卡信息"];
    
    phoneNum.keyboardType = UIKeyboardTypeNumberPad;
    
    [self setData];
    
}

- (void)setData{
    
    bankNameTf.text = [BankCarList sharedInstance].addParametersModel.bankName;
}

- (IBAction)onNextBtn:(UIButton *)sender {
    
    [self.view endEditing:YES];
    
    if (bankNameTf.text.length <= 0) {
        
        return [self showMBPError:@"填写银行名称"];
    }
    
    if (bankTypeTf.text.length <= 0) {
        
        return [self showMBPError:@"填写卡类型"];
    }
    
    if (phoneNum.text.length <= 0) {
        
        [self showMBPError:@"填写手机号"];
        return;
    }
    
    if (![phoneNum.text isVaildMobileNo]) {
        
        return [self showMBPError:@"填写正确手机号"];
        
    }
    
    [BankCarList sharedInstance].addParametersModel.bankName = bankNameTf.text;
    [BankCarList sharedInstance].addParametersModel.type = bankTypeTf.text;
    [BankCarList sharedInstance].addParametersModel.phone = phoneNum.text;

    ConfirmPhoneNumViewController *VC = [[ConfirmPhoneNumViewController alloc] init];
    VC.phoneNum = phoneNum.text;
    [self.navigationController pushViewController:VC animated:YES];
}

#pragma mark - 选择银行
- (IBAction)onSelectBandBtn:(UIButton *)sender {
    
    [self.view endEditing:YES];
    
    
    NSArray *arr =  [[[NSDictionary alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"bandList" ofType:@"plist"]] objectForKey:@"band"];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"选择银行" preferredStyle:UIAlertControllerStyleActionSheet];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    for (NSString *a in arr) {
        
        [alert addAction:[UIAlertAction actionWithTitle:a style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            self->bankNameTf.text = a;
        }]];
    }
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}


#pragma mark - 选择银行类型
- (IBAction)onSelectBandTypeBtn:(UIButton *)sender {
    
    [self.view endEditing:YES];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"选择卡类型" preferredStyle:UIAlertControllerStyleActionSheet];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"借记卡" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->bankTypeTf.text = @"借记卡";
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"信用卡" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->bankTypeTf.text = @"信用卡";
    }]];
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}

@end
